fix(cli): publish cli/package.json so --cli metadata lookup works from the installed package#1702
Open
n0liu wants to merge 1 commit into
Open
Conversation
…m the installed package The root package `files` allowlist did not include `cli/package.json`, so it was absent from the published npm tarball. `cli/build/index.js` imports `../package.json` to read the CLI name and version for the client identity; when the process working directory happens to have a sibling `package.json`, the existing cwd-relative `fs.existsSync` probe selects that module-relative `../package.json` (i.e. `cli/package.json`), which is not shipped, and every `--cli` invocation dies with `ERR_MODULE_NOT_FOUND` (broken since v0.17.0). Adding `cli/package.json` to `files` makes both resolution targets present in the tarball, so the metadata import always succeeds. Verified with `npm pack --dry-run`: the file is absent before this change and present after. Fixes modelcontextprotocol#1503
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The CLI (
--climode) is broken from v0.17.0 through v0.22.0: invocations can fail immediately withERR_MODULE_NOT_FOUNDforcli/package.json.cli/build/index.jsreads../package.jsonto get the CLI name and version for the client identity. The root packagefilesallowlist shipscli/buildbut notcli/package.json, so that file is absent from the published npm tarball. The current cwd-relativefs.existsSync("../package.json")probe selects the module-relative../package.json(which resolves tocli/package.json) whenever the process working directory happens to have a siblingpackage.json, and the dynamic import then fails because the file was never published.Adding
cli/package.jsontofilesmakes both resolution targets present in the tarball, so the metadata import always resolves.This is the packaging half of the problem; #1337 separately hardens the runtime resolution to be module-relative. The two are complementary and touch different files (
package.jsonhere vscli/src/index.tsthere).Type of Change
How verified
npm pack --dry-runat the repo root (lifecycle scripts skipped for the file listing):cli/package.jsonis absent from the packed file listcli/package.jsonis present in the packed file listRelated
Fixes #1503